# -*- coding: utf-8 -*-
# @Time    : 2021/11/13 21:02
# @Author  : travel2040
# @Email   : travel2040@163.com
# @File    : opencv-合成视频.py
# 需要安装的库
# pip install opencv_python

import cv2

def createVideo(input_address, output_address):
    cap = cv2.VideoCapture(input_address)
    cap_fps = int(cap.get(cv2.CAP_PROP_FPS))

    fourcc = cv2.VideoWriter_fourcc(*"FLV1")

    fps = 25
    width = 1280
    height = 720
    video_writer = cv2.VideoWriter(output_address, fourcc, fps, (width, height))

    frame_num = 0
    while True:
        ret, frame = cap.read()

        if ret:
            frame_num += 1
            cv2.imshow("frame", frame)
            video_writer.write(frame)

            if cv2.waitKey(10) & 0xff == ord('q'):
                break
            if frame_num > 1000:
                break
            # print("current frame_num ",frame_num)
        else:
            break

    video_writer.release()
    cap.release()
    cv2.destroyAllWindows()


if __name__ == '__main__':

    input_address = "test.mp4"
    output_address = "test.flv"
    createVideo(input_address, output_address)